package Demo;

/**
 * 自定义异常
 */
public class Demo_2 {
    public String userName = "abc";
    public String passWord = "123";
    public void loginInfo(String userName,String passWord)
            throws userNameException, passWordException {
        if(!this.userName.equals(userName)) {
            //System.out.println("用户名输入有误...");
            throw new userNameException("用户名输入有误...");//在异常中提示"用户名输入有误..."
        }
        if(!this.passWord.equals(passWord)) {
            //System.out.println("用户名输入有误...");
            throw new passWordException("密码输入有误...");//在异常中提示"密码输入有误..."
        }
        System.out.println("登录成功...");
    }
    public static void main2(String[] args) {
        Demo_2 demo_2 = new Demo_2();
        try{//处理异常，
            demo_2.loginInfo("abc","1234");
        } catch (userNameException e){
            System.out.println("userNameException...");
        } catch(passWordException e) {
            System.out.println("passWordException...");
        }

        System.out.println("程序继续执行...");//处理异常后 异常后的语句继续执行
    }
    public static void main(String[] args)
            throws passWordException, userNameException {
        Demo_2 demo_2 = new Demo_2();
        demo_2.loginInfo("abc","1234");
        //未处理异常时不会向后执行
        System.out.println("程序继续执行...");
    }
}
